package jianzhiOffer;

import java.util.ArrayList;
import java.util.List;

public class Num34 {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    public List<List<Integer>> pathSum(TreeNode root, int target) {
        dfs(root,target);
        return res;
    }
    public void dfs(TreeNode root,int target) {
        if(root == null) return;
        target -= root.val;
        path.add(root.val);
        if(target == 0 && root.left == null && root.right == null) {
            res.add(new ArrayList(path));
            path.remove(path.size() - 1);
            return;
        }
        dfs(root.left,target);
        dfs(root.right,target);
        path.remove(path.size() - 1);
    }
}
